﻿//---------------------------------------------------------------------
//Copyright (c) 2009, Pierre Milet
//All rights reserved.
//
//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
//INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
//IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, 
//OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
//PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
//TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
//---------------------------------------------------------------------
using System;
using System.Diagnostics;
using Microsoft.BizTalk.TransportProxy.Interop;
using Microsoft.BizTalk.Component.Interop;
using Microsoft.Samples.BizTalk.Adapter.Common;

namespace BizMock.Adapter.Runtime
{
    /// <summary>
    /// Summary description for BizMockReceiveEndpoint.
    /// </summary>
    internal class BizMockReceiverEndpoint : ReceiverEndpoint
    {
        private BizMockReceiveProperties    properties        = null;
        private string url;

        public BizMockReceiverEndpoint()
        {
        }

        public override void Open(string uri, IPropertyBag config, IPropertyBag bizTalkConfig, IPropertyBag handlerPropertyBag, IBTTransportProxy transportProxy, string transportType, string propertyNamespace, ControlledTermination control)
        {
            this.url = uri;
            Debug.WriteLine(string.Format("BizMockReceiveEndpoint.BizMockReceiveEndpoint( url:{0} ) open", url), "BizMockReceive: Info");

            this.properties = new BizMockReceiveProperties(url);
            this.properties.LocationConfiguration(config, bizTalkConfig);
        }

        public override void Update(IPropertyBag config, IPropertyBag bizTalkConfig, IPropertyBag handlerPropertyBag)
        {
            Debug.WriteLine(string.Format("BizMockReceiveEndpoint.Update( url:{0} ) update", url), "BizMockReceive: Info" );

            // Read the new configuration...
            BizMockReceiveProperties newProps = new BizMockReceiveProperties(url);
            newProps.LocationConfiguration(config, bizTalkConfig);

            // Update the configuration...
            this.properties = newProps;
        }

        public BizMockReceiveProperties Configuration
        { 
            get { return this.properties; }
        }
    }
}
